package com.bone;

import java.io.InputStream;
import java.net.Socket;
import java.util.HashMap;

public abstract class HttpRequest {
    // -------------------- 属性 -----------------------
    /**
     * 请求行相关定义
     */
    private String message; //报文
    private String method; //请求方法
    private String url; //抽象路径
    private String protocol; //协议.

    /**
     * 请求路径部分
     */
    private String requestURI; //v.12.抽象路径中的请求部分?左
    private String queryString; //v.12.抽象路径中的参数, ?右

    /**
     * 参数
     */
    private HashMap<String, String> parameters = new HashMap<>();

    /**
     * 请求头
     */
    private HashMap<String, String> headers = new HashMap<>();


    /**
     * 与连接相关的属性, 解析三步骤通用.
     * 传过来的Socket,获取的流.
     */
    private Socket socket;
    private InputStream is;

//     --------------------------- 方法 --------------------------

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getProtocol() {
        return protocol;
    }

    public void setProtocol(String protocol) {
        this.protocol = protocol;
    }

    public String getRequestURI() {
        return requestURI;
    }

    public void setRequestURI(String requestURI) {
        this.requestURI = requestURI;
    }

    public String getQueryString() {
        return queryString;
    }

    public void setQueryString(String queryString) {
        this.queryString = queryString;
    }

    public HashMap<String, String> getParameters() {
        return parameters;
    }

    public void setParameters(HashMap<String, String> parameters) {
        this.parameters = parameters;
    }

    public HashMap<String, String> getHeaders() {
        return headers;
    }

    public void setHeaders(HashMap<String, String> headers) {
        this.headers = headers;
    }

    public Socket getSocket() {
        return socket;
    }

    public void setSocket(Socket socket) {
        this.socket = socket;
    }

    public InputStream getIs() {
        return is;
    }

    public void setIs(InputStream is) {
        this.is = is;
    }
//    -------------------- 抽象方法 -----------------------

    /**
     * 解析请求行
     */
    public abstract void parseRequestLine() throws Exception;

    /**
     * 解析资源路径
     */
    public abstract void parseRequestUrl();

    /**
     * 解析请求头
     */
    public abstract void parseHeader();

    /**
     * 解析请求体
     */
    public abstract void parseContent();

}
